package tr.edu.metu.is550.isell.rest.jersey.provider.mapper;

import tr.edu.metu.is550.isell.domain.ApplicationException;
import tr.edu.metu.is550.isell.rest.message.ErrorMessages;

import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;

public abstract class
        AbstractApplicationExceptionMapper<T extends ApplicationException> implements ExceptionMapper<T> {
    @Override
    public Response toResponse(ApplicationException exception) {
        return Response.status(responseStatus())
                .entity(
                        new ErrorMessages().add(
                                exception.getErrorCode(),
                                exception.getErrorMessage(),
                                exception.getArgs()
                        )
                )
                .build();

    }

    abstract Response.Status responseStatus();
}
